package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsOrderMapper;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsStorage;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private DtsOrderMapper dtsOrderMapper;


    @Override
    public int countOrder() {
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);
        Integer count = dtsOrderMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public List<DayStatis> incrCount() {
        List<DayStatis> list = dtsOrderMapper.staticsIncresOrderCnt();
        return list;
    }

    @Override
    public List<CategorySellAmts> categoryCount() {
        List<CategorySellAmts> list = dtsOrderMapper.categorySell();
        return list;
    }

    @Override
    public IPage<DtsOrder> queryStoragePage(Integer id, String name, Integer page, Integer limit, String sort, String order) {
        //创建分页对象
        IPage<DtsOrder> ipage = new Page<>(page, limit);

        //封装查询对象
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted", false);

        if (!StringUtils.isEmpty(id)) {
            queryWrapper.eq("id", id);
        }
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            if (order.equalsIgnoreCase("asc")) {
                queryWrapper.orderByAsc(sort);
            } else {
                queryWrapper.orderByDesc(sort);
            }
        }
        IPage<DtsOrder> resultPage = dtsOrderMapper.selectPage(ipage, queryWrapper);

        return resultPage;

    }
}
